import {defineStore} from "pinia";
import {ref} from "vue"
import {listKnowledgeAPI, addKnowledgeAPI, delKnowledgeAPI, modifyKnowledgeAPI, detailKnowledgeAPI} from "@/apis/knowledge.js";

export const useKnowledgeStore = defineStore('knowledge', ()=> {
    const knowledgeList = ref([])

    // 查全部
    const listKnowledge = async () => {
        const res = await listKnowledgeAPI()
        knowledgeList.value = res.data.data
    }

    // 添加
    const addKnowledge = async (formData) => {
        const res = await addKnowledgeAPI(formData)
        return res.data
    }

    // 删除
    const delKnowledge = async (data) => {
        const res = await delKnowledgeAPI(data)
        return res.data
    }

    // 更新
    const modifyKnowledge = async (data) => {
        const res = await modifyKnowledgeAPI(data)
        return res.data
    }

    // 查单个
    const detailKnowledge = async (data) => {
        const res = await detailKnowledgeAPI(data)
        // console.log(res.data)
        return res.data
    }

    return {
        knowledgeList, listKnowledge, addKnowledge, delKnowledge, modifyKnowledge, detailKnowledge
    }



})